import pytest
import time

from common.NeqReq import NeqReq
from common.DBManager import DBManager

from utils.yaml_utils import read_yaml
from utils.url_utils import full_url
from utils.data_process_utils import extract_args


url = "/login/verifyLogin"
data_path = "./data/login.yaml"
pre_path = "./data/setup/login.yaml"

class Test_login:
    
    @pytest.fixture(scope="class",  autouse=True)
    def class_cycle(self):

        dm = DBManager()   
        pre_data = read_yaml(pre_path)
        dm.insert_data(pre_data['table'], pre_data['fields'], pre_data['data'])
        yield
        dm.close()


    @pytest.mark.parametrize("args", read_yaml(data_path))
    def test_1(self,args):
        
        data = extract_args(args, ['username','pwd','append'],['username','password','append'])

        nr = NeqReq()
        result = nr.send_request('GET', full_url(url), data)

        assert result['code'] == args['exp1']
        if result['code'] == 200:
            assert result['body'].get('code') == args['exp2']

